﻿using System.Collections.Generic;
using DynConDevCorp.OpenArch.SmartData.Interfaces;

namespace DynConDevCorp.OpenArch.SmartData.Interfaces
{
    /// <summary>
    /// Type Safe Interface for collections of ISmartEntity objects which have a primary key.
    /// </summary>
    /// <typeparam name="TKey">The type of the Key.</typeparam>
    /// <typeparam name="TEntity">The type of the Entity.</typeparam>
    public interface ISmartEntityKeyedCollection<TKey, TEntity> : ISmartEntityCollection<TEntity> //, ISmartFieldKeyedCollection<TKey,TEntity>
        where TEntity : ISmartEntity
    {
        #region Public Instance Properties

        /// <summary>
        /// Gets the <see cref="ISmartEntity"/> instance with the specified key.
        /// </summary>
        /// <value></value>
        TEntity this[TKey key] { get; }

        /// <summary>
        /// Gets the index keys.
        /// </summary>
        /// <value>The index keys.</value>
        IList<TKey> IndexKeys { get; }

        #endregion

        #region Public Instance Methods

        /// <summary>
        /// Adds the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="entity">The entity.</param>
        void Add(TKey key, TEntity entity);

        /// <summary>
        /// Removes the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        bool Remove(TKey key);

        /// <summary>
        /// Gets the entity.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        TEntity GetEntity(TKey key);

        /// <summary>
        /// Determines whether [contains] [the specified key].
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns>
        /// 	<c>true</c> if [contains] [the specified key]; otherwise, <c>false</c>.
        /// </returns>
        bool Contains(TKey key);

        /// <summary>
        /// Tries the get value.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        bool TryGetValue(TKey key, out TEntity entity);

        /// <summary>
        /// Tries the get key.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        bool TryGetKey(TEntity entity, out TKey key);

        /// <summary>
        /// Gets the index key.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        TKey GetIndexKey(TEntity item);

        #endregion
    }
}